package com.itheima.controller;

import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Category;
import com.itheima.pojo.Spec;
import com.itheima.service.CategoryService;
import com.itheima.service.SpecService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    @GetMapping("/findPage")
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = specService.findPage(queryPageBean);
        System.out.println("测试1");
        return pageResult;
    }

    @GetMapping("/findAllSpecWithOptions")
    public Result findAllSpecWithOptions(Integer category3id) {
        List<Map> resultList = specService.findAllSpecWithOptions(category3id);
        return new Result(true, "查询成功", resultList);
    }

    @PostMapping
    public Result handleAdd(@RequestBody Spec spec) {
        return specService.handleAdd(spec);
    }

    @DeleteMapping("/{id}")
    public Result handleDelete(@PathVariable("id") Integer id) {
        return specService.handleDelete(id);
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return specService.findById(id);
    }

    @PutMapping
    public Result update(@RequestBody Spec spec) {
        return specService.update(spec);
    }



}
